#include "qs_config.h"
#include "qs_log.h"
#include "qs_sched.h"
#include "qs_pwm.h"
#include "qs_misc.h"
#include "qs_aip650.h"

typedef struct {
    uint8_t number;
    int8_t num_disp;
    uint8_t pic;
}qs_misc_disp_data_t;

static qs_misc_disp_data_t m_disp_data;
static uint8_t beep_timeout_timer = 0;



static void on_misc_20ms_handle(void)
{

    
    qs_pwm_buzz_set(beep_timeout_timer > 0 ?true:false);
    if(beep_timeout_timer > 0) {
        beep_timeout_timer --;
    }
}


void qs_misc_beep_once(void)
{
    beep_timeout_timer = 2;
}

void qs_misc_long_beep(void)
{
    beep_timeout_timer = 5;
}

void qs_misc_number_set(uint8_t num, int8_t disp_enable)
{
    m_disp_data.number = num;
    m_disp_data.num_disp = disp_enable;
}
void qs_misc_pic_set(uint8_t num,uint8_t mask)
{
    if(num == 3)  qs_aip650_digi_data_send(4, 0);
    else if(num == 4) qs_aip650_digi_data_send(3, mask & 0x04);
    
    
    qs_aip650_digi_data_send(num, mask);
}
void qs_misc_init(void)
{
    memset(&m_disp_data, 0 ,sizeof(m_disp_data));
    qs_on_misc_20ms_handle_set(on_misc_20ms_handle);
}